/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lolbuilder.runes;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import lolbuilder.Champions.Interf.DummyChamp;
import lolbuilder.masteries.BestDpsMasteriesChoose;
import lolbuilder.params.Duo;
import lolbuilder.params.Parameters;

/**
 *
 * @author chocoboSan
 */
public class RunesCompoCalculator {
     public static  ArrayList<Runes> marks=new ArrayList<Runes>();
     public static  ArrayList<Runes> seals=new ArrayList<Runes>();
     public static  ArrayList<Runes> glyphs=new ArrayList<Runes>();
     public static  ArrayList<Runes> quints=new ArrayList<Runes>();
     
    public static void main(String[] args) {
        BestDpsMasteriesChoose.main(args);
        RunesCompoCalculator.load("build\\classes\\lolbuilder\\runes\\blue",glyphs,"blue");
        RunesCompoCalculator.load("build\\classes\\lolbuilder\\runes\\red",marks,"red");
        RunesCompoCalculator.load("build\\classes\\lolbuilder\\runes\\quint",quints,"quint");
        RunesCompoCalculator.load("build\\classes\\lolbuilder\\runes\\yellow",seals,"yellow");
        ArrayList<ArrayList<Runes>> marksCompos=new ArrayList<ArrayList<Runes>>();
        ArrayList<ArrayList<Runes>> glyphsCompos=new ArrayList<ArrayList<Runes>>();
        ArrayList<ArrayList<Runes>> sealsCompos=new ArrayList<ArrayList<Runes>>();
        ArrayList<ArrayList<Runes>> quintCompos=new ArrayList<ArrayList<Runes>>();
        for (Runes r0 : marks) {
            for (Runes r1 : marks) {
                for (Runes r2 : marks) {
                    for (Runes r3 : marks) {
                        for (Runes r4 : marks) {
                            for (Runes r5 : marks) {
                                for (Runes r6 : marks) {
                                    for (Runes r7 : marks) {
                                        for (Runes r8 : marks) {
                                            ArrayList<Runes> tmp=new ArrayList<Runes>();
                                            tmp.add(r0);
                                            tmp.add(r1);
                                            tmp.add(r2);
                                            tmp.add(r3);
                                            tmp.add(r4);
                                            tmp.add(r5);
                                            tmp.add(r6);
                                            tmp.add(r7);
                                            tmp.add(r8);
                                            marksCompos.add(tmp);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        for (Runes r0 : glyphs) {
            for (Runes r1 : glyphs) {
                for (Runes r2 : glyphs) {
                    for (Runes r3 : glyphs) {
                        for (Runes r4 : glyphs) {
                            for (Runes r5 : glyphs) {
                                for (Runes r6 : glyphs) {
                                    for (Runes r7 : glyphs) {
                                        for (Runes r8 : glyphs) {
                                            ArrayList<Runes> tmp=new ArrayList<Runes>();
                                            tmp.add(r0);
                                            tmp.add(r1);
                                            tmp.add(r2);
                                            tmp.add(r3);
                                            tmp.add(r4);
                                            tmp.add(r5);
                                            tmp.add(r6);
                                            tmp.add(r7);
                                            tmp.add(r8);
                                            glyphsCompos.add(tmp);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        for (Runes r0 : seals) {
            for (Runes r1 : seals) {
                for (Runes r2 : seals) {
                    for (Runes r3 : seals) {
                        for (Runes r4 : seals) {
                            for (Runes r5 : seals) {
                                for (Runes r6 : seals) {
                                    for (Runes r7 : seals) {
                                        for (Runes r8 : seals) {
                                            ArrayList<Runes> tmp=new ArrayList<Runes>();
                                            tmp.add(r0);
                                            tmp.add(r1);
                                            tmp.add(r2);
                                            tmp.add(r3);
                                            tmp.add(r4);
                                            tmp.add(r5);
                                            tmp.add(r6);
                                            tmp.add(r7);
                                            tmp.add(r8);
                                            sealsCompos.add(tmp);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        for (Runes r0 : quints) {
            for (Runes r1 : quints) {
                for (Runes r2 : quints) {
                    ArrayList<Runes> tmp=new ArrayList<Runes>();
                    tmp.add(r0);
                    tmp.add(r1);
                    tmp.add(r2);
                    quintCompos.add(tmp);
                }
            }
        }
        for (Iterator<ArrayList<Runes>> it = marksCompos.iterator(); it.hasNext();) {
            ArrayList<Runes> arrayList = it.next();
            Collections.sort(arrayList);
        }
        for (Iterator<ArrayList<Runes>> it = glyphsCompos.iterator(); it.hasNext();) {
            ArrayList<Runes> arrayList = it.next();
            Collections.sort(arrayList);
        }
        for (Iterator<ArrayList<Runes>> it = sealsCompos.iterator(); it.hasNext();) {
            ArrayList<Runes> arrayList = it.next();
            Collections.sort(arrayList);
        }
        for (Iterator<ArrayList<Runes>> it = quintCompos.iterator(); it.hasNext();) {
            ArrayList<Runes> arrayList = it.next();
            Collections.sort(arrayList);
        }
        RunesCompoCalculator.removeDuplicate(marksCompos);
        
        RunesCompoCalculator.removeDuplicate(glyphsCompos);
        
        RunesCompoCalculator.removeDuplicate(sealsCompos);
        
        RunesCompoCalculator.removeDuplicate(quintCompos);
        
        ArrayList<Duo<ArrayList<Runes>,RBS>> res=new ArrayList<Duo<ArrayList<Runes>,RBS>>();
        
        float bestDPS=0;
        ArrayList<Runes> bestrunesForDPS=null;
        int i=0;
        System.out.println("i start calculating the best runes");
        for (ArrayList<Runes> arM : marksCompos) {
            for (ArrayList<Runes> arS : sealsCompos) {
                for (ArrayList<Runes> arG : glyphsCompos) {
                    for (ArrayList<Runes> arQ : quintCompos) {
                        RBS r=new RBS();
                        ArrayList<Runes> tmp=new ArrayList<Runes>();
                        tmp.addAll(arM);
                        tmp.addAll(arS);
                        tmp.addAll(arG);
                        tmp.addAll(arQ);
                        for (Runes ru : tmp) {
                            ru.addMyBonus(r);
                        }
                        DummyChamp dc=null;
                        try {
                            dc=Parameters.champUsedForAd.getClass().newInstance();
                        } catch (InstantiationException ex) {
                            Logger.getLogger(RunesCompoCalculator.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IllegalAccessException ex) {
                            Logger.getLogger(RunesCompoCalculator.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        r.addAllBonus(dc);
                        dc.calculateDpsOver100sec();
                        if (dc.dpsOver100sec>bestDPS) {
                            bestrunesForDPS=new ArrayList<Runes>(tmp);
                            bestDPS=dc.dpsOver100sec;
                            for (Runes ru : tmp) {
                                Parameters.r=new RBS();
                                ru.addMyBonus(Parameters.r);
                            }
                        
                        }
                    }
                }
            }
            i++;
            System.out.println((((float)i-1)/arM.size()/6)*100+"% done");
        }
        System.out.println(bestrunesForDPS);
        
}
    
    
    public static void load(String path,ArrayList<Runes> array,String color) {
        File file = new File(path);
	File[] listOfFiles = file.listFiles();
        Object locItem;
        File buildfolder=new File("build\\classes\\");
        for (File f : listOfFiles) {
            if (f.isFile()) {
                if (f.getName().split("\\.")[1].equals("java")) {
                    try {
                        // Convert File to a URL
                        URL url = buildfolder.toURL();;
                        URL[] urls = new URL[]{url};

                        // Create a new class loader with the directory
                        ClassLoader loader = new URLClassLoader(urls);

                        // Load in the class; Class.childclass should be located in
                        // the directory file:/c:/class/user/information
                        locItem=loader.loadClass("lolbuilder.runes."+color+"."+f.getName().split("\\.")[0]).newInstance();
                        array.add((Runes) locItem);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
     
    }
    
        /** List order not maintained **/
        public static void removeDuplicate(ArrayList arlList) {
            HashSet h = new HashSet(arlList);
            arlList.clear();
            arlList.addAll(h);
        }
}
